package com.linkhub.oms.common.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.base.Splitter;
import com.linkhub.oms.common.enums.IEnumConvert;
import com.linkhub.oms.common.enums.product.LocalProductLogisticsAttributeEnum;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Jaycle
 * @version 1.0.0
 * @Description WmsUtil.java
 * @createTime 2024/06/19 21:22
 */
public class WmsUtil {
    public static String createItemCode( String userId, String skuId ) {
        return userId + "_" + skuId;
    }

    public static String getUserId(String itemCode) {
        List<String> splits = StrUtil.split(itemCode, "_");
        return CollUtil.getFirst(splits);
    }

    public static String getSkuId(String itemCode) {
        List<String> splits = StrUtil.split(itemCode, "_");
        return CollUtil.getLast(splits);
    }

    public static String createSkuProperty( List<Integer> logisticsAttributeList ) {
        String skuProperty = logisticsAttributeList.stream()
                .map(logisticsAttribute -> IEnumConvert.valueOf(logisticsAttribute, LocalProductLogisticsAttributeEnum.class).getCnName())
                .collect(Collectors.joining(","));
        // WMS限制skuProperty为200字符串
        return skuProperty.length() > 200 ? skuProperty.substring(0, 200) : skuProperty;
    }

    public static String createBarCode( String sysBarCode, String upc, String fnsku, String otherCode ) {
        return Arrays.asList(sysBarCode, upc, fnsku, otherCode).stream()
                .filter(s -> s != null && !s.isEmpty())
                .collect(Collectors.joining(";"));
    }
}
